<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page isELIgnored ="false" %>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %> 
<%@ taglib uri="/WEB-INF/tld/sys.tld" prefix="sys" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
	<meta charset="UTF-8">
    <title>产品列表</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true" />
</head>

<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="searchBar">
        <div class="fieldset1 clearFix">
        	<div class="fieldBox">
                <div class="label">产品编码</div>
                <div class="field">
                    <input name="prdId" id="prdId" type="text" class="ui-textbox" value="">
                </div>
            </div>
        	<div class="fieldBox">
                <div class="label">产品名称</div>
                <div class="field">
                    <input name="prdNm" id="prdNm" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox">
                <div class="label">产品类型</div>
                <div class="field">
                	<input name="prdTypCd" id="prdTypCd" type="text" value="" placeholder="请选择" ltype="combobox">
                </div>
            </div>
            <div class="fieldBox">
                <div class="label">产品型号</div>
                <div class="field">
                    <input name="prdMdl" id="prdMdl" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox">
                <div class="label">产品品牌</div>
                <div class="field">
                	<input type="text" name="brCd" id="brCd" placeholder="请选择"/>
                </div>
            </div>
            <div class="fieldBox">
                <div class="label">厂商名称</div>
                <div class="field">
                    <input name="mfrNm" id="mfrNm" type="text" class="ui-textbox" value="">
                </div>
            </div>
            <div class="fieldBox">
                <div class="label">审核状态</div>
                <div class="field">
                    <select name="audStsCd" id="audStsCd" data-value=" ">
                    	<option value=" " seleted>请选择</option>
                       <c:forEach items="${searchAudStsCdList }" var="kv">
                     		<option value="${kv.key }">${kv.value }</option>
                       </c:forEach>
                    </select>
                </div>
            </div>
            <div class="fieldBox">
                <div class="label">产品驱动</div>
                <div class="field">
                    <select name="drvTyp" id="drvTyp" data-value=" ">
                    	<option value=" " seleted>请选择</option>
                       <c:forEach items="${searchDrvTypList }" var="kv">
                     		<option value="${kv.key }">${kv.value }</option>
                       </c:forEach>
                    </select>
                </div>
            </div>
            <div class="fieldBox">
                <div class="label">产品马力</div>
                <div class="field">
                    <select name="hp" id="hp" data-value=" ">
                    	<option value=" " seleted>请选择</option>
                       <c:forEach items="${searchHpList }" var="kv">
                     		<option value="${kv.key }">${kv.value }</option>
                       </c:forEach>
                    </select>
                </div>
            </div>
            <div class="fieldBox">
                <div class="label">待审核子产品</div>
                <div class="field">
                    <select name="isHaveNeedCheckChildPrd" id="isHaveNeedCheckChildPrd" data-value=" ">
                    	<option value=" " seleted>请选择</option>
                     	<option value="1">是</option>
                     	<option value="0">否</option>
                    </select>
                </div>
            </div>
            <div class="clearFix"></div>
            <div class="btnsBox formBtns notRight">
               <span id="searchBtn" class="sq-button-round">查询</span>
                <span id="clearBtn" class="sq-button-round">清空</span>
                <span id="addBtn" class="sq-button-round">新增</span>
                <%--<span id="exportbtn" class="sq-button-round" onclick="exportProduct();">导出</span>--%>
                <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
            	<%-- <span class="sq-button sq-button-hasicon">
            		<i class="sqBtnIco_8"></i>
	                <a href="<%=path%>/system/sysulfilesrec/downLoad.do?filePath=${downFilePath}&fileName=${downFileName}">下载模板</a>
            	</span> --%>
            </div>
            <%-- <div class="btnsBox" id="btnsBox">
            	<div class="fieldBox col_100">
            		<div class="field">
	                    <jsp:include page="../../system/sysUlFilesRec/sysSysUlFilesRecUpload.jsp" flush="true" >
							<jsp:param name="fileNum" value="1"/>
							<jsp:param name="filePath" value="product/exportPrd"/>
						</jsp:include>
					</div>
				</div>
                <span id="addBatchBtn" class="sq-button sq-button-hasicon" onclick="addBatch();"><i class="sqBtnIco_33"></i>批量导入</span>
                <span id="errorDownload" class="sq-button sq-button-hasicon">
            		<i class="sqBtnIco_8"></i>
	                <a href="">下载错误日志</a>
				</span>
            </div> --%>
        </div>
    </form>
</div>
<div class="sqPanel" style="margin-bottom: 0;">
    <div class="sqPanel_head" style="float:left;color: red">
        <table class="table_full">
            <tr>
                <td>
                	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><i class="ico_flasher"></i></b>有待审核子产品
                </td>
            </tr>
        </table>
    </div>
    <div class="sqPanel_body">
        <div id="ligergrid1" class="sq-grid"></div>
    </div>
</div>
<!-- <div id="ligergrid1" class="sq-grid"></div> -->
</div>

<!-- 是否显示提交按钮 -->
<sys:funcAuth resCd="PrdSubmit">
	<span id="isShowCmtBtn" />
</sys:funcAuth>
<!-- 是否显示审核按钮  启用禁用按钮 -->
<sys:funcAuth resCd="PrdCheck">
	<span id="isShowAudBtn" />
</sys:funcAuth>

<script type="text/javascript">
	var grid = null;
	var _mfrId = '${mfrId}';
	$(function () {
		$("#errorDownload").hide();
		var _url = '<%=path%>/product/prdBscInfo/initList.do?mfrId='+_mfrId ;
	    grid = $("#ligergrid1").ligerGrid({
	    	url:_url ,
	    	method : 'get',
	        columns: [
				{ display: '<span class="sqiconfont sqicon-tishi c_sqYellow gridTip" title="有待审核子产品"></span>', 
					name: '',width: 30,
					render: function (rowdata, rowindex, value) {
				        if (StringUtils.isNotEmpty(rowdata.isHaveNeedCheckChildPrd) && rowdata.isHaveNeedCheckChildPrd == 1) var ico_flasher_h='<i class="ico_flasher"></i>'
				            else ico_flasher_h='';
				        var h = ico_flasher_h;
				        return h;
				    }	
				},
	            { display: '产品编码', name: 'id',align:'left', width: 150},
	            { display: '产品名称', name: 'prdNm',align:'left', width: 100,
	            	render: function (rowdata, rowindex, value){
	            		var h='<a href="javascript:showDetail(';
	            		h+="'"+rowdata.id+"'";
	                    h+=')">'+rowdata.prdNm+'</a>';
	                	return h;
	            	}	
	            },
	            { display: '产品类型', name: 'prdTypCdNm',align:'left', width: 100},
	            { display: '产品型号', name: 'prdMdl',align:'left', width: 100 },
	            { display: '厂商名称', name: 'mfrNm',align:'left', minWidth: 200},
	            { display: '品牌', name: 'brCdNm',align:'left', width: 100},
	            { display: '使用状态', name: 'isValidNm', width: 80 },
	            { display: '审核状态', name: 'audStsCdNm', width: 80},
	            { 
	            	display: '操作',minWidth: 350,align:'left',
	            	render: function (rowdata, rowindex, value){
	            		var v;
                        var v1='<a class="sq-button-hasicon" href="javascript:;" onclick="disable(';
                            v1+="'"+rowdata.id+"'";
                            v1+=')"><i class="sqBtnIco_13"></i>'+LogUtils.LOG_CMM_GRID_BTN_DISABLE+'</a>';
                            
                        var v2='<a class="sq-button-hasicon" href="javascript:;" onclick="enable(';
                            v2+="'"+rowdata.id+"'";
                            v2+=')"><i class="sqBtnIco_12"></i>'+LogUtils.LOG_CMM_GRID_BTN_ENABLE+'</a>';
                    	switch (rowdata.isValid){
                           case 0:
                               v=v2;
                               break;
                           case 1:
                               v=v1;
                               break;
                           default:
                           	v=v1;
                           	break;
                        }
            			var b='<a class="sq-button-hasicon" href="javascript:modifyAudStsCd(';
			                b+="'"+rowdata.id+"'";
			                b+=",'"+FlowConstant.FLOW_CHECK_STATE_IN+"'";
			                b+=')"><i class="sqBtnIco_22"></i>提交</a>';
            			var h='<a class="sq-button-hasicon" href="javascript:changeAudStsCd(';
			                h+="'"+rowdata.id+"'";
			                h+=')"><i class="sqBtnIco_6"></i>审核</a>';
	            		var g='<a class="sq-button-hasicon" href="javascript:change(';
		            		g+="'"+rowdata.id+"'";
		                    g+=')"><i class="sqBtnIco_4"></i>修改</a>';
                    	var d='<a class="sq-button-hasicon" href="javascript:deleteRecord(';
		            		d+="'"+rowdata.id+"'";
		                    d+=')"><i class="sqBtnIco_7"></i>删除</a>';
                    	var tk='<a class="sq-button-hasicon" href="javascript:toTruckList(';
		            		tk+="'"+rowdata.id+"'";
		                    tk+=')"><i class="sqBtnIco_1"></i>产品明细</a>';
		                
		                var isAudStsCd = rowdata.isAudStsCd;//是否需要审核(乘用车 专车 没有审核过程 默认就是审核通过)
	                    var isShowCmtBtn = $("#isShowCmtBtn");
	                    var isShowAudBtn = $("#isShowAudBtn");
	                    var end = "";
	                    //需要审核的产品:才有可能有提交/审核
	                    if(isAudStsCd==1){
		                    //有提交权限 && 审核状态:待提交||审核不通过 -->提交按钮显示
		                    if(isShowCmtBtn.length){
		                    	if(rowdata.audStsCd==FlowConstant.FLOW_CHECK_STATE_NON || rowdata.audStsCd==FlowConstant.FLOW_CHECK_STATE_NO_PASS)
		                    	end += b;
		                    }
		                    //有审核权限  显示启用禁用
		                    if(isShowAudBtn.length){
		                    	end+=v;
		                    	// 有审核权限 && 审核状态!=待提交 -->审核按钮显示
		                    	if(rowdata.audStsCd!=FlowConstant.FLOW_CHECK_STATE_NON){
			                    	end += h;
		                    	}
		                    }
		                    //有提交权限&& 审核状态:待提交||审核不通过  -->修改删除显示
		                    if(isShowCmtBtn.length){
		                    	if(rowdata.audStsCd == FlowConstant.FLOW_CHECK_STATE_NON || rowdata.audStsCd == FlowConstant.FLOW_CHECK_STATE_NO_PASS){
			                    	end += g;
			                    	end += d;
		                    	}
		                    }
		                    end += tk;
	                    }else{//不需要审核的产品:提供  启用禁用/修改/删除  操作
	                    	//有审核权限  显示启用禁用
		                    if(isShowAudBtn.length){
		                    	end+=v;
		                    }
		                  	//有提交权限
	                    	if(isShowCmtBtn.length){
	                    		end+=g;
	                    		end+=d;
	                    	}
	                    }
	                    
			            return end;
	            	}
				}
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        //isScroll: false,
	        checkbox:false,
	        rownumbers:true,
	        allowUnSelectRow:true,
	        alternatingRow: true,
	        enabledSort:false,
	        /* onRenderComplete: function () {
	        	iframeResize ();
	        } */
	    });
	    grid.setHeight(100);
	    //*****************产品类型下拉树******************************/
		$("#prdTypCd").ligerComboBox({
	            // width: 178,
	            selectBoxWidth: 240,
	            selectBoxHeight: 150,
	            treeLeafOnly: false, //限制只能选叶节点，父节点不能点击
	            textField:"tName",
	            valueField:"tCode",
	            tree: {
	                url: '<%=path%>/product/prdBscInfo/getPrdTyeDataForSearch.do',
	                ajaxType: 'get',
	                checkbox: false,
	                parentIcon: "none",
	                childIcon: "none",
	                textFieldName:"tName",
	                idFieldName:"tCode",
	                onSuccess: function () {
	                    var treeselect=liger.get("prdTypCd");
	                    //treeselect.setValue("Q");
	                }
	            }
	        });
	    
	    $("#searchBar").ligerForm();
	    
		//
	    $("#brCd").ligerComboBox({
            url: '<%=path%>/product/prdBscInfo/getCurrentBrCdJSON.do',
            ajaxType: "get",
            //parms:{mTypCd:'M0002', sGrpCd:_sGrpCd, sCode:_sCode},
            width: 178,
            valueField: 'key',
    		textField: 'value',
            autocomplete: function (e){
                filter_autoComboboxData(e.key, this);
                e.show();
            },
            onChangeValue: function (value) {
            	if (this.findValueByText(value) == "") {//清除输入值
                    liger.get("brCd").setValue("");
                }
            }
        });
	    //$("#pageloading").hide();
	    
	    $("#searchBtn").click(function(event) {
	         var form = new liger.get("searchBar");
	         var data = form.getData();
	         for (name in data){
	        	 if(name!="brCd"){
		            grid.setParm(name,data[name]);
	        	 }
	         };
	         grid.setParm("brCd",liger.get("brCd").getValue());//品牌
	         grid.reload();
	    });
	    $("#clearBtn").click(function(event) {
	        $("#resetBtn").click();  //重置 input-text
	        var form = liger.get("searchBar");
	        form.setData({  //重置select等特殊表单
	            "brCd": " ",
	            "audStsCd": " ",
	            "drvTyp": " ",
	            "hp": " ",
	            "isHaveNeedCheckChildPrd": " ",
	        });
	        liger.get("prdTypCd").clear();//清空产品类型下拉树的值
	    });
	
	    $("#addBtn").click(function(event) {
			//回调刷新列表
			var callback = function () {
				grid.reload();
            };
            Add_navTab("Prd_1"+Date.parse(new Date()), "新增产品", '<%=path%>/product/prdBscInfo/toAddPage.do?mfrId='+_mfrId , callback)
		});
});
	var callback = function () {
		grid.reload();
    };
    
    //审核
	function changeAudStsCd(_id){
		//跳转修改页面,传递参数isShowAuditBtn,标识可以审核此产品(修改审核状态)
		Add_navTab('Prd_Aud'+_id,'审核产品信息','<%=path%>/product/prdBscInfo/toAddPage.do?isShowAuditBtn=1&id='+_id , callback)
		
		<%-- $.ligerDialog.SQopen({
            width: 500,
            height:200,
            title : '审核信息',
            url:'<%=path%>/product/prdBscInfo/toModifyAudStsCdPage.do?id='+_id,
            buttons: [{
	                text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onOk) Dialog.onOk();
	                }
	            }, {
	                text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
	                onclick: function (item, Dialog) {
	                    if (Dialog.onCancel) Dialog.onCancel();
	                }
	            }
	        ]
        }); --%>
	}
	function change(_id){
		if(!_id)return;
		if(_mfrId==""){
            Add_navTab('Prd_2'+_id,'修改产品信息','<%=path%>/product/prdBscInfo/toAddPage.do?id='+_id , callback)
		}else{
			Add_navTab('Prd_2'+_id,'修改产品信息','<%=path%>/product/prdBscInfo/toAddPage.do?id='+_id+'&mfrId='+_mfrId , callback)
		}
	}
	function toTruckList(_id){
		if(!_id)return;
		Add_navTab('tk_1'+_id,'产品明细',"<%=path%>/product/prdBscInfo/toAddPage.do?isLink=1&id="+_id);
	}
	function showDetail(_id){
		if(!_id)return;
		parent.parent.mainApp.f_addTab('Prd_3'+_id,'查看产品信息','<%=path%>/product/prdBscInfo/toDetailPage.do?id='+_id)
	}
	//删除数据
	function deleteRecord(id){
		if(!id)return;
		
		var _ids = [];
		_ids.push(id);
		$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{ids:JSON.stringify(_ids)},
				url: '<%=path%>/product/prdBscInfo/removeByIds.do',
				beforeSend: function(){
				     wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING,SQ_type:"waitting"});
				},
				success:function(msg){
					wait_dialog.close();
					 if(msg.success == 1){
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						 grid.reload();
					 }else{
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				}
			});
		});
	}
	//批量导入
	function addBatch(){
		var value = getUploadResultParams();
		//alert(JSON.stringify(value));
		if(value){
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				data:{value:JSON.stringify(value)},
				url: '<%=path%>/product/prdBscInfo/addBatch.do',
				beforeSend: function(){
			          wait_dialog=$.ligerDialog.SQalert({content: '正在导入产品信息...' ,SQ_type: "waitting" });
			     },
				success:function(msg){
					wait_dialog.close();
					 if(msg.success == 1){
						 if(msg.data.flag==0 || msg.data.verifyFlag==0){	//批量增加没有全部添加成功  或  excel-->javaObject校验失败
							 $.ligerDialog.SQalert({content:msg.data.massage, SQ_type: "warning"});
							 $("#errorDownload").show();
							 var _href = "<%=path%>/system/sysulfilesrec/downLoad.do?filePath="+ msg.data.downFilePath +"&fileName="+msg.data.downFileName;
							 $("#errorDownload").attr("href",_href);
						 }else{	//校验成功 批量增加全部添加成功
							 $.ligerDialog.SQalert({content:msg.data.massage, SQ_type: "success"});
							 $("#errorDownload").hide();
							 grid.reload();
						 }
					 }else{
						 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				}
			});
		}else{
			$.ligerDialog.SQalert({content:"请先上传产品表格", SQ_type: "warning"});
		}
	}
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}
	//提交  修改审核状态(审核中)
	function modifyAudStsCd(_id,_audStsCd){
	    if(!_id || !_audStsCd)return;
	    //提交审核确认  2017-6-8 by YAOXIURONG
        $.ligerDialog.confirm(FlowConstant.SUBMIT_AUDIT_CONFIRM, function (flag) {
			if(flag == false)return;
		    var url = '<%=path%>/product/prdBscInfo/modifyAudStsCd.do';
		    var wait_dialog;
		    $.ajax({
				type: 'post',
				dataType:'json',
				data:{
					id:_id,
					audStsCd:_audStsCd
				},
				url: url,
				beforeSend: function(){
			          wait_dialog=top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
			     },
				success:function(msg){
					 wait_dialog.close();
					 if(msg.success == 1){
						 top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
						 grid.reload();
					 }else{
						 top.$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					 }
				}
			});
        });
	}
	//启用
	function enable(id){
		if(!id)return;
		$.ligerDialog.confirm(LogUtils.LOG_CMM_ENABLE_CONFIRM, function (flag) {
   			if(flag == false)return;
   			$.ajax({
   				type: 'post',
   				dataType:'json',
   				data:{id:id},
   				url: '<%=path%>/product/prdBscInfo/enable.do',
   				success:function(msg){
   					 if(msg.success == 1){
   						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
   						grid.reload();
   					 }else{
   						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
   					 }
   				}
   			});
   		});
	}
	function disable(id){
		if(!id)return;
		$.ligerDialog.confirm(LogUtils.LOG_CMM_DISABLE_CONFIRM, function (flag) {
   			if(flag == false)return;
   			$.ajax({
   				type: 'post',
   				dataType:'json',
   				data:{id:id},
   				url: '<%=path%>/product/prdBscInfo/disable.do',
   				success:function(msg){
   					 if(msg.success == 1){
   						$.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
   						 grid.reload();
   					 }else{
   						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
   					 }
   				}
   			});
   		});
	}
	//导出
	function exportProduct(){
		var form = new liger.get("searchBar");
        var data = form.getData();
		var wait_dialog;
		$.ajax({
			type: 'get',
			url: '<%=path%>/product/prdBscInfo/exportProduct.do?',
			data:data,
			dataType:'json',
			beforeSend:function(){
				wait_dialog=$.ligerDialog.SQalert({content: '导出中,请稍后...',SQ_type: "waitting"});
			},
			success:function(msg){
				wait_dialog.close();
				if(msg.success == 1){
					window.open(msg.data);
				}else{
					$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
				}
			} 
		});
	}
</script>

</body>
</html>